/*
 * @lc app=leetcode.cn id=985 lang=javascript
 *
 * [985] 查询后的偶数和
 */

// @lc code=start
/**
 * @param {number[]} A
 * @param {number[][]} queries
 * @return {number[]}
 */
var sumEvenAfterQueries = function(A, queries) {
    let res=[]
    let sum=0
    for(let i of A){
        if(i%2==0){
            sum+=i
        }
    }
    for(let item of queries){
       let temp=A[item[1]]+item[0]
       if(A[item[1]]%2==0){
        if(item[0]%2==0){
            sum+=item[0]
        }else{
            sum-=A[item[1]]
        }
       }else{
        if(item[0]%2!=0){
            sum+=item[0]+A[item[1]]
        }
       }
       res.push(sum)
       A[item[1]]=temp
    }
    return res
};  
// @lc code=end

